/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ApuestaVS.java
 *
 * Created on 05-ene-2012, 20:37:37
 */

package GUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import logica.Apuesta;
import logica.Evento;
import logica.Participante;

/**
 *
 * @author andresgodoysalavert
 */
public class ApuestaVS extends javax.swing.JFrame {

    Evento evento = new Evento();
    Apuesta apuesta = new Apuesta();

    public void llenarPantalla(int idEv) throws SQLException{
        Participante array[] = evento.getParticipantesVS(idEv);
        
        this.jLabel6.setText(String.valueOf(array[0].getId()));
        this.jTextField1.setText(array[0].getNombre());
        this.jLabel1.setText("Relacion de Pago: "+array[0].getPago());
        this.jLabel1.setForeground(Color.orange);

        this.jLabel7.setText(String.valueOf(array[1].getId()));
        this.jTextField2.setText(array[1].getNombre());
        this.jLabel2.setText("Relacion de Pago: "+array[1].getPago());
        this.jLabel2.setForeground(Color.orange);
    }


    /** Creates new form ApuestaVS */
    public ApuestaVS(int id) throws SQLException {
        initComponents();
        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width, (int) (screenSize.height));
        this.jLayeredPane1.setBounds(0,0,screenSize.width, screenSize.height);
        this.jPanel1.setBounds(0,0,screenSize.width, screenSize.height);
        this.jPanel1.setLayout(null);
        this.jLabel5.setBounds(0,0,screenSize.width, screenSize.height-100);
        this.jTextField1.setBounds((screenSize.width*1/4)-200,screenSize.height/3,400,100);
        this.jTextField2.setBounds((screenSize.width*3/4)-200,screenSize.height/3,400,100);
        this.jLabel1.setBounds((screenSize.width*1/4)-200,screenSize.height/3+70,400,100);
        this.jLabel2.setBounds((screenSize.width*3/4)-200,screenSize.height/3+70,400,100);
        this.jLabel3.setBounds((screenSize.width/2)-(this.jLabel3.getWidth()/2),screenSize.height/3,400,100);
        this.jToggleButton1.setBounds((screenSize.width*1/4)-80,screenSize.height/3+180,200,100);
        this.jToggleButton2.setBounds((screenSize.width*3/4)-80,screenSize.height/3+180,200,100);
        this.jButton1.setBounds((screenSize.width*1/2)-250,screenSize.height-300,150,50);
        this.jButton2.setBounds((screenSize.width*1/2)+100,screenSize.height-300,150,50);
        this.jButton1.setText("Volver");
        this.jButton2.setText("Confirmar");
        this.jLabel4.setBounds((screenSize.width/2)-300,100,1000,100);
        this.jLabel8.setText(String.valueOf(id));
        llenarPantalla(id);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(153, 153, 153));
        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jTextField1.setEditable(false);
        jTextField1.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        jTextField1.setText("jTextField1");
        jTextField1.setDragEnabled(false);

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 24));
        jLabel1.setText("jLabel1");

        jTextField2.setEditable(false);
        jTextField2.setFont(new java.awt.Font("Lucida Grande", 0, 36)); // NOI18N
        jTextField2.setText("jTextField1");
        jTextField2.setDragEnabled(false);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 24));
        jLabel2.setText("jLabel1");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vs.png"))); // NOI18N

        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton2ActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/backarrow.png"))); // NOI18N
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setBackground(new java.awt.Color(30, 142, 58));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/check.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/farana 1 small.png"))); // NOI18N

        jLabel6.setForeground(new java.awt.Color(153, 153, 153));
        jLabel6.setText("jLabel6");

        jLabel7.setForeground(new java.awt.Color(153, 153, 153));
        jLabel7.setText("jLabel7");

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/marco3.png"))); // NOI18N

        jLabel8.setForeground(new java.awt.Color(153, 153, 153));
        jLabel8.setText("jLabel8");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(185, 185, 185)
                                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(45, 45, 45)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jLabel7)
                                        .add(1661, 1661, 1661)
                                        .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jToggleButton1)
                                        .add(79, 79, 79)
                                        .add(jToggleButton2))
                                    .add(jLabel6))))
                        .add(462, 462, 462)
                        .add(jLabel3))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(458, 458, 458)
                        .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(139, 139, 139)
                        .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jButton1)
                        .add(97, 97, 97)
                        .add(jButton2))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(310, 310, 310)
                        .add(jLabel8)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(149, 149, 149)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(540, Short.MAX_VALUE)))
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(476, 476, 476)
                    .add(jLabel5)
                    .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(189, 189, 189)
                .add(jLabel8)
                .add(595, 595, 595)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(61, 61, 61)
                        .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(42, 42, 42)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel3)))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(44, 44, 44)
                        .add(jLabel6)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel7)))
                .add(663, 663, 663)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jToggleButton1)
                    .add(jToggleButton2))
                .add(693, 693, 693)
                .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(41, 41, 41)
                        .add(jLabel1))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(66, 66, 66)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButton1)
                            .add(jButton2))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addContainerGap(2360, Short.MAX_VALUE)
                    .add(jLabel2)
                    .add(246, 246, 246)))
            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(918, 918, 918)
                    .add(jLabel5)
                    .addContainerGap(918, Short.MAX_VALUE)))
        );

        jPanel1.setBounds(0, 0, 840, 560);
        jLayeredPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 841, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLayeredPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 564, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        // TODO add your handling code here:
       if (this.jToggleButton1.isSelected()) {
            this.jToggleButton2.setSelected(false);
            jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
            jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsgold.png")));
       }else{
            this.jToggleButton2.setSelected(true);
            jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsgold.png")));
            jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
       }
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
        // TODO add your handling code here:
      if (this.jToggleButton2.isSelected()) {
            this.jToggleButton1.setSelected(false);
            jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
            jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsgold.png")));
       }else{
            this.jToggleButton1.setSelected(true);
            jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsgold.png")));
            jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/images/vsblack.png")));
       }
    }//GEN-LAST:event_jToggleButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            // TODO add your handling code here:
            this.setVisible(false);
            GUI.Principal p = new GUI.Principal(null);
            p.setVisible(true);
        } catch (SQLException ex) {
            Logger.getLogger(ApuestaVS.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //insertar apuesta
        String factura = "        Farana Bets C.A.\n    Caracas - Venezuela RIF - J-00012255-5\n       La Urbina";
        try{
            int monto=Integer.parseInt(JOptionPane.showInputDialog(null,"Inserte el monto a apostar: ","Monto de Apuesta",JOptionPane.WARNING_MESSAGE));
            if(jToggleButton1.isSelected()){
                int max=evento.getMontoApuesta(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel6.getText()));
                if(max<=monto){
                    JOptionPane.showMessageDialog(null,"No puede apostar esa cantidad!","Error",JOptionPane.WARNING_MESSAGE);
                }else{
                    apuesta.insertarApuesta(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel6.getText()), monto, 1);
                    factura = factura + apuesta.getApuesta() + "\n"+ evento.getParticipanteFactura(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel6.getText()));
                        pdf p=new pdf(factura);
                        p.setVisible(true);
                        p.setBounds(500, 250, 400, 400);
                        p.setDefaultCloseOperation(EXIT_ON_CLOSE);
                        p.setLocationRelativeTo(null);
                        this.setVisible(false);
                        Principal principal = new Principal(null);
                        p.setVisible(true);
                }
            }
            else if(jToggleButton2.isSelected()){
                int max=evento.getMontoApuesta(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel7.getText()));
                if(max<=monto){
                    JOptionPane.showMessageDialog(null,"No puede apostar esa cantidad!","Error",JOptionPane.WARNING_MESSAGE);
                }else{
                    apuesta.insertarApuesta(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel7.getText()), monto, 1);
                    factura = factura + apuesta.getApuesta() + "\n"+ evento.getParticipanteFactura(Integer.parseInt(jLabel8.getText()), Integer.parseInt(jLabel7.getText()));
                        pdf p=new pdf(factura);
                        p.setVisible(true);
                        p.setBounds(500, 250, 400, 400);
                        p.setDefaultCloseOperation(EXIT_ON_CLOSE);
                        p.setLocationRelativeTo(null);
                        this.setVisible(false);
                        Principal principal = new Principal(null);
                        p.setVisible(true);
                }
            }else{

            }
        }
        catch (IOException ex) {
            Logger.getLogger(ApuestaVS.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex) {
            Logger.getLogger(ApuestaVS.class.getName()).log(Level.SEVERE, null, ex);
        }
        catch(NumberFormatException e){
            JOptionPane.showMessageDialog(null,"Solo puede introducir numeros!","Error",JOptionPane.WARNING_MESSAGE);
        }


    }//GEN-LAST:event_jButton2ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new ApuestaVS(0).setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(ApuestaVS.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    // End of variables declaration//GEN-END:variables

}
